package Jets.loader
{
	import flash.display.Loader;
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.events.IEventDispatcher;
	import flash.events.IOErrorEvent;
	import flash.net.URLLoader;
	import flash.net.URLLoaderDataFormat;
	import flash.net.URLRequest;
	import flash.utils.setTimeout;
	
	import Jets.interfaces.InJLoader;
	
	public class JLoader extends EventDispatcher implements InJLoader
	{
		public function JLoader(target:IEventDispatcher=null)
		{
			super(target);
		}

		public function onLoader(url:String, type:int, callFun:Function):void
		{
			var loader:JLoaderBase = new JLoaderBase(type,callFun);
			switch(type)
			{
				case JLoaderType.Load_Type_Txt:
				case JLoaderType.Load_Type_Xml:
					break;
				case JLoaderType.Load_Type_BinFile:
					loader.dataFormat = URLLoaderDataFormat.BINARY;
					break;
				case JLoaderType.Load_Type_Image:
					break;
				case JLoaderType.Load_Type_Swf:
					break
				default:
					return;
			}
			if(loader)
			{
				loader.addEventListener(Event.COMPLETE,onLoadCompleted);
				loader.load(new URLRequest(url));
			}
		}
		
		private function onLoadCompleted(event:Event):void
		{
			setTimeout((event.target as JLoaderBase).callFun,1,event);
		}
		
		private function onLoadError(err:IOErrorEvent):void
		{
			trace(err.text);
		}
	}
}